package com.landcode.netty.config;

import io.netty.channel.nio.NioEventLoopGroup;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;


@Configuration
public class NettyConfig {

    //@Value("${tcp.port}")
    private int tcpPort = 8672;

    //@Value("${boss.thread.count}")
    private int bossCount = 5;

    //@Value("${worker.thread.count}")
    private int workerCount = 4;

    //@Value("${so.keepalive}")
    private boolean keepAlive = true;

    //@Value("${so.backlog}")
    private int backlog = 1000;

    @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully")
    public NioEventLoopGroup bossGroup() {
        return  new NioEventLoopGroup(bossCount);
    }

    @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully")
    public NioEventLoopGroup workerGroup() {
        return new NioEventLoopGroup(workerCount);
    }

    @Bean("inetSocketAddress")
    public InetSocketAddress inetSocketAddress() {
        return new InetSocketAddress(tcpPort);
    }
}
